package com.cssw.fyzb.tps.api.vod;

import com.cssw.fyzb.tps.client.VodClient;
import com.cssw.fyzb.tps.model.vo.AuditResultVo;
import com.cssw.fyzb.tps.model.vo.UploadVodVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Feng Chen
 */
@Function(description = "添加视频", parameters = {
        @Parameter(name = "media", type = Type.String, description = "视频地址", required = true),
        @Parameter(name = "cover", type = Type.String, description = "封面地址", required = true),
}, result = @Result(properties = {
        @Property(name = "fileId", type = Type.String, description = "文件编号"),
        @Property(name = "mediaUrl", type = Type.String, description = "视频地址"),
        @Property(name = "coverUrl", type = Type.String, description = "封面地址"),
}))
@Component
public class UploadVod implements Action {

    @Autowired
    private VodClient vodClient;

    private static final Logger logger = LoggerFactory.getLogger(UploadVod.class);

    @Override
    public Response execute(Request request) throws Exception {
        String media = request.getString("media");
        String cover = request.getString("cover");

        try {
            UploadVodVo vo = vodClient.uploadVod(media, cover);
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.error("", e);
        }

        return Response.fail("操作异常");
    }

}
